//
//  BaseTabBarVC.swift
//  BUYOU
//
//  Created by tyuu on 2024/5/28.
//

import UIKit
import SwifterSwift


class BaseTabBarVC: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        addChildViewController(RunMainVC(), imageName: "img_6fwpjun2", selImgName: "img_p4enumw5")
        addChildViewController(PubRunVC(), imageName: "img_my4jm909", selImgName: "img_gnc9eb45")
        addChildViewController(MeViewController(), imageName: "img_excfynj0", selImgName: "img_828qr19j")
    }
    
    
    func addChildViewController(_ childViewController: UIViewController, withTitle title: String = "", imageName: String, selImgName: String) {
        // 设置子视图控制器的标题
        childViewController.title = title
        childViewController.tabBarItem.title = title
        
        // 设置标签栏项的图
        childViewController.tabBarItem.image = UIImage(named: "\(imageName)")?.withRenderingMode(.alwaysOriginal)
        childViewController.tabBarItem.selectedImage = UIImage(named: "\(selImgName)")?.withRenderingMode(.alwaysOriginal)
        
        // 定义选中和未选中状态的颜色
        let selectedColor = UIColor(hex: 0x8367F6)
        let normalColor = UIColor(hex: 0xAAAAAA)
        
        // 设置字体大小
        let fontSize = UIFont.boldSystemFont(ofSize: 12)
        
        // 根据iOS版本设置标签栏的颜色和文本属性
        tabBar.tintColor = selectedColor
        tabBar.unselectedItemTintColor = normalColor
        childViewController.tabBarItem.setTitleTextAttributes([.font: fontSize], for: .normal)
        
        
        // 将子视图控制器嵌入导航控制器中，并添加为子控制器
        let navigationController = BaseNavVC(rootViewController: childViewController)
        addChild(navigationController)
    }
    
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destination.
     // Pass the selected object to the new view controller.
     }
     */
    
}
